import pandas as pd

import joblib

from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# CSV = "电影__机器训练__数据集.csv"
# MODEL = 'movie.plk'
# PATH = "C:\\Users\\Administrator\\Desktop\\data"
# file = f'{PATH}\\{CSV}'
# df = pd.read_csv(file)
#
# tag_map = {0: '爱情', 1: '动作'}
# reversed_dict = {v: k for k, v in tag_map.items()}
#
# df.drop('电影名称', axis=1, inplace=True)
# X = df.loc[:, df.columns != '电影分类'].values
# pd.set_option('future.no_silent_downcasting', True)
#
# for key in reversed_dict.keys():
#     df["电影分类"] = df["电影分类"].replace(key, reversed_dict[key])
#
# df["电影分类"] = df["电影分类"].astype(int)
# y = df.loc[:, "电影分类"].values
#
# print(y)
#
# knn = KNeighborsClassifier(n_neighbors=10)
# X_train, X_test, y_train, y_test = \
#     train_test_split(X, y, test_size=0.25, random_state=42)
# # 训练
# for i in range(1000):
#     knn.fit(X_train, y_train)
# # 预测测试集
# y_pred = knn.predict(X_test)
# # 计算精准度
# ascore = accuracy_score(y_test, y_pred)
# print('Accuracy:', ascore)
#
# joblib.dump(knn, f'{PATH}\\{MODEL}')

